package com.wink_172.library.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;

import androidx.databinding.DataBindingUtil;

import com.wink_172.library.R;
import com.wink_172.library.databinding.ActivityPlayImageBinding;
import com.wink_172.library.utils.FileUtil;
import com.wink_172.library.view.ActionBarView;

import org.xutils.image.ImageOptions;
import org.xutils.x;

/**
 * 播放单个图片源
 */
public class PlayImageActivity extends SmartActivity {
    public ActivityPlayImageBinding binding;

    public static void startActivity(Context context, Object... args) {
        Intent intent = new Intent(context, PlayImageActivity.class);
        intent.putExtra(com.wink_172.library.model.Constants.PARAM_DATA1, (int) args[0]);
        intent.putExtra(com.wink_172.library.model.Constants.PARAM_DATA2, (String) args[1]);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding = DataBindingUtil.setContentView(this, R.layout.activity_play_image);
        binding.setOnClickListener(this);
        initView();
        init();
    }

    public void initView() {
        ((ActionBarView) binding.actionBar).setBackground(null);
        ((ActionBarView) binding.actionBar).setLineEnable(false);

        ((ActionBarView) binding.actionBar).updateAllContent(R.mipmap.icon_back, "", "");
        ((ActionBarView) binding.actionBar).setCallback(new ActionBarView.ICallback() {
            @Override
            public void onSendEvent(int event, String content) {
                if (event == ActionBarView.LEFT_BTN) {
                    finish();
                }
            }
        });
    }

    private final String TAG = "PlayImageActivity";

    private void init() {
        String url = getIntent().getStringExtra(com.wink_172.library.model.Constants.PARAM_DATA2);
        ((ActionBarView) binding.actionBar).content.setText(FileUtil.Companion.getFileNameWithSuffix(url));

        Log.e(TAG, "init: ====>>" + url);
        ImageOptions options = new ImageOptions.Builder()
                .setUseMemCache(true)
//                .setFadeIn(true)
                .setImageScaleType(ImageView.ScaleType.CENTER)
                .build();

        x.image().bind((ImageView) binding.imageView, url, options);

    }
}